//
//  rush_list_three.m
//  K-Music
//
//  Created by CHUN on 16/1/18.
//  Copyright © 2016年 CHUN. All rights reserved.
//

#import "rush_list_three.h"


@interface rush_list_three ()<UITableViewDataSource,UITableViewDelegate,UIAlertViewDelegate>
{
    
    NSMutableArray* all_Data ;
}

@property (nonatomic, strong) UITableView * Three_TableView;


@end

@implementation rush_list_three

- (void)viewDidLoad {
    [super viewDidLoad];
    [self get_consumed];
    // Do any additional setup after loading the view.
}

-(void)get_consumed{
    
    [MBProgressHUD showWithStatus:@"加载中..." toView:self.view];
    
    [SameWay downloadData:@"E" andCallback:^(id obj) {
        NSLog(@"===========:%@",obj);
        
        all_Data=[NSMutableArray array];
        
        all_Data = obj;
        NSLog(@"%@",all_Data);
        
        [User_information conversion].consumed_Data = obj;
        
        
        [self get_Month_consumed];
        
    }];
}

-(void)get_Month_consumed{

    
    [SameWay downloadData:@"F" andCallback:^(id obj) {
        NSLog(@"===========:%@",obj);
        
        all_Data = [NSMutableArray array];
        
        all_Data = obj;
        
        NSLog(@"%@",all_Data);
        
        [User_information conversion].Month_consumed_Data = obj;
        
        [self createUI];
        
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    }];
}


- (void)createUI
{
    _Three_TableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT-99) style:UITableViewStyleGrouped];
    _Three_TableView.delegate = self;
    _Three_TableView.dataSource = self;
    _Three_TableView.showsVerticalScrollIndicator = NO;
    _Three_TableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _Three_TableView.backgroundColor = RGB(241, 241, 241);
    [self.view addSubview:_Three_TableView];
    
}

#pragma mark ------- UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 50;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 100;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 4;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellID = @"cellID";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    
    UIImageView * icon;
    
    A_Music * data =[[A_Music alloc]init];
    NSArray *arr;
    switch (indexPath.section) {
        case 0:
            arr = [User_information conversion].consumed_Data;
            break;
            
        case 1:
            arr = [User_information conversion].Month_consumed_Data;
            break;
    }
    
    if (cell == nil) {
        
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellID];
        icon = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 80, 80)];
        data  = arr[0];
        
        [icon sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",data.avatar]]];
        icon.layer.cornerRadius= 40;
        icon.layer.masksToBounds = YES;
        
        [cell.contentView addSubview:icon];
        
        UILabel * mylabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(icon.frame)+30, 20, WIDTH/2, 30)];
        mylabel.text=[NSString stringWithFormat:@"%@",data.nickName];
        mylabel.textColor=[UIColor orangeColor];
        mylabel.textAlignment=NSTextAlignmentLeft;
        [cell.contentView addSubview: mylabel];
        
        UILabel * name = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(icon.frame)+30, 60, WIDTH/4, 30)];
        name.text = [NSString stringWithFormat:@"%@",data.userId];
        name.textColor=[UIColor grayColor];
        name.textAlignment=NSTextAlignmentLeft;
        [cell.contentView addSubview: name];
        
        UILabel * totalPlay = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(name.frame), 60, WIDTH/2, 30)];
        totalPlay.text = [NSString stringWithFormat:@"粉丝:%@ 人关注",data.fanNumber];
        totalPlay.textColor=[UIColor grayColor];
        totalPlay.textAlignment=NSTextAlignmentLeft;
        [cell.contentView addSubview: totalPlay];
        
        
    }
    
    return cell;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    UIView *View = [[UIView alloc]init];
    View.backgroundColor = [UIColor whiteColor];
    View.userInteractionEnabled = YES;
    
    UIButton *butt = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, WIDTH, 50)];
    butt.tag = section;
    butt.backgroundColor = [UIColor whiteColor];
    [butt addTarget:self action:@selector(ppp:) forControlEvents:(UIControlEventTouchUpInside)];
    [View addSubview:butt];
    
    
    UILabel * name = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, WIDTH/2, 50)];
    if (section == 0) {
        name.text = @"|  最火财富总榜";
    }
    else
    {
        name.text = @"|  本月财富总榜";
    }
    
    name.textColor=[UIColor orangeColor];
    name.textAlignment=NSTextAlignmentLeft;
    [View addSubview: name];
    
    
    UILabel * more = [[UILabel alloc]initWithFrame:CGRectMake( WIDTH-100 , 0, 80, 50)];
    more.text = @"全部 >>";
    more.textColor=[UIColor orangeColor];
    more.textAlignment=NSTextAlignmentRight;
    [View addSubview:more];
    
    return View;
}

-(void)ppp:(UIButton*)button{
    
    NSLog(@"1-%ld",(long)button.tag);
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    YYplayerVC*yy=[[YYplayerVC alloc]init];
    
    yy.hidesBottomBarWhenPushed = YES;
    
    yy.musicData= [User_information conversion].musicData[indexPath.row];
    
    [yy setTracks:[Track remoteTracks]];
    [self.navigationController pushViewController:yy animated:NO];
    
    
    [tableView deselectRowAtIndexPath:tableView.indexPathForSelectedRow animated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
